Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

fix issue with session_id#91

Merged
jhaynie merged 1 commit intomainfrom
fix-issue-with-session
Aug 28, 2025
Merged

fix issue with session_id#91
jhaynie merged 1 commit intomainfrom
fix-issue-with-session

Conversation

@jhaynie
Copy link
Copy Markdown
Member

@jhaynie jhaynie commented Aug 28, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Standardized run and session IDs to a formatted string, ensuring consistency across responses, logs, and integrations with tracing tools.
  • Tests

    • Expanded tests to simulate real tracing flows and validate deterministic ID formatting.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 28, 2025

Walkthrough

Updated handle_agent_request to format the OpenTelemetry trace_id using format_trace_id and ensure session_id is a string. Tests were adjusted to mock tracer/span/format_trace_id and assert tracing behavior.

Changes

Cohort / File(s) Summary
Server tracing ID formatting
agentuity/server/__init__.py
Use format_trace_id(span.get_span_context().trace_id) for run_id when span is recording; set AgentContext.session_id to str(run_id).
Tests for tracing path
tests/server/test_request_handlers.py
Mock tracer/span/format_trace_id; ensure get_tracer("http-server") is used; validate formatted trace id is applied in handle_agent_request.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant Server as HTTP Server
  participant Tracer as OTel Tracer
  participant Span as Span
  participant OTel as format_trace_id
  participant Agent as AgentContext

  Client->>Server: HTTP request
  Server->>Tracer: start_span("handle_agent_request")
  Tracer-->>Server: Span
  Server->>Span: is_recording()
  alt recording
    Server->>Span: get_span_context().trace_id
    Server->>OTel: format_trace_id(trace_id)
    OTel-->>Server: formatted_trace_id
    Server->>Agent: session_id = str(formatted_trace_id)
  else not recording
    Server->>Agent: session_id = None / existing logic
  end
  Server-->>Client: Response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • jsw324

Poem

I traced a line through carrot fields bright,
A span of sunlight, formatted just right.
My session hops with stringy delight,
Ears up, logs neat, requests in flight.
Hop, hop—run_id shines, a tidy byte! 🥕✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-issue-with-session

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot requested a review from jsw324 August 28, 2025 22:11
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
agentuity/server/__init__.py (2)

369-371: Wrong variable when extracting scope from nested x-agentuity-metadata.

You’re checking “scope” in metadata, but the parsed JSON is in md.

Apply this diff:

-                                            if "scope" in metadata:
+                                            if "scope" in md:
                                                 scope = md["scope"]
                                                 del md["scope"]

396-401: Same bug in top-level x-agentuity-metadata handling.

Check md, not metadata.

Apply this diff:

-                                if "scope" in metadata:
+                                if "scope" in md:
                                     scope = md["scope"]
                                     del md["scope"]
🧹 Nitpick comments (1)
tests/server/test_request_handlers.py (1)

102-106: Good: patch format_trace_id; also assert session_id is propagated.

Strengthen the test by verifying the AgentContext.session_id passed to run_agent equals "test-trace-id".

Add after awaiting handle_agent_request:

# Verify session_id propagated to AgentContext
mock_run_agent.assert_awaited()
args, kwargs = mock_run_agent.call_args
agent_context = args[-1]
assert getattr(agent_context, "session_id") == "test-trace-id"
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between b2e8610 and fd0d04b.

📒 Files selected for processing (2)
  • agentuity/server/__init__.py (3 hunks)
  • tests/server/test_request_handlers.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/server/test_request_handlers.py (3)
tests/server/test_agent.py (1)
  • mock_tracer (50-55)
tests/server/test_agent_execution.py (1)
  • mock_tracer (18-23)
tests/conftest.py (1)
  • mock_tracer (7-9)
🔇 Additional comments (2)
agentuity/server/__init__.py (2)

14-14: Import of format_trace_id is appropriate.

This aligns with OTel’s API and enables stable 32-char hex IDs.


347-349: Correct: format trace_id to a string run_id.

Using format_trace_id(...) ensures a canonical string run_id for propagation and logging.

Comment on lines +450 to 452
session_id=str(run_id),
scope=scope,
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Bug: session_id becomes the literal string "None" when tracing isn’t recording.

str(run_id) coerces None → "None". Downstream code will see a non-empty session_id, which is misleading.

Apply this diff:

-                    session_id=str(run_id),
+                    session_id=run_id,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
session_id=str(run_id),
scope=scope,
)
session_id=run_id,
scope=scope,
)
🤖 Prompt for AI Agents
In agentuity/server/__init__.py around lines 450 to 452, session_id is set using
str(run_id) which converts None into the literal string "None" and misleads
downstream code; change this to pass None when run_id is None (e.g., session_id
= None if run_id is None else str(run_id)) so that an absent run_id remains a
true None rather than the string "None".

Comment on lines +91 to +99
# Create a mock span with proper trace_id formatting
mock_span_context = MagicMock()
mock_span_context.trace_id = 12345678901234567890123456789012345678
mock_span = MagicMock()
mock_span.get_span_context.return_value = mock_span_context
mock_span.is_recording.return_value = True
mock_tracer = MagicMock()
mock_tracer.start_span.return_value.__enter__.return_value = mock_span

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Mock the API you actually use: start_as_current_span, not start_span.

handle_agent_request uses tracer.start_as_current_span(...). Your mock wires start_span, so the configured span (is_recording, get_span_context) isn’t the one used.

Apply this diff:

-        mock_tracer = MagicMock()
-        mock_tracer.start_span.return_value.__enter__.return_value = mock_span
+        mock_tracer = MagicMock(spec=trace.Tracer)
+        mock_tracer.start_as_current_span.return_value.__enter__.return_value = mock_span
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Create a mock span with proper trace_id formatting
mock_span_context = MagicMock()
mock_span_context.trace_id = 12345678901234567890123456789012345678
mock_span = MagicMock()
mock_span.get_span_context.return_value = mock_span_context
mock_span.is_recording.return_value = True
mock_tracer = MagicMock()
mock_tracer.start_span.return_value.__enter__.return_value = mock_span
# Create a mock span with proper trace_id formatting
mock_span_context = MagicMock()
mock_span_context.trace_id = 12345678901234567890123456789012345678
mock_span = MagicMock()
mock_span.get_span_context.return_value = mock_span_context
mock_span.is_recording.return_value = True
- mock_tracer = MagicMock()
mock_tracer = MagicMock(spec=trace.Tracer)
mock_tracer.start_as_current_span.return_value.__enter__.return_value = mock_span
🤖 Prompt for AI Agents
In tests/server/test_request_handlers.py around lines 91 to 99, the test mocks
tracer.start_span but the code under test calls tracer.start_as_current_span, so
the span used in the handler isn’t the mocked one; update the mock to set
mock_tracer.start_as_current_span.return_value.__enter__.return_value =
mock_span (and keep mock_span.get_span_context, mock_span.is_recording as is) so
the context manager used by start_as_current_span yields the configured mock
span.

@jhaynie jhaynie merged commit 02c8ff8 into main Aug 28, 2025
5 checks passed
@jhaynie jhaynie deleted the fix-issue-with-session branch August 28, 2025 22:16
devin-ai-integration Bot added a commit that referenced this pull request Aug 28, 2025
- Add entry for v0.0.105 with session_id formatting fix
- Include PR #91 reference
- Add version comparison link

Co-Authored-By: unknown <>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants